//
//  MeatSearchHeader.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/1.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatSearchHeader.h"

@interface MeatSearchHeader()<UITextFieldDelegate>

@end


@implementation MeatSearchHeader

#pragma mark - lifecycle methods

- (void)setupUI
{
    [self addSubview:self.leftNavBtn];
    [self addSubview:self.navView];
}


- (void)setupLayout
{
    self.height = TJ_NavBarHeight;
    
    {
        _leftNavBtn.frame = CGRectMake(15, TJ_StatusBarHeight_Define, 44,  44);
    }
    
    {
        _navView.mj_x = 50;
        _navView.mj_y = TJ_StatusBarHeight_Define + 5;
        _navView.size = CGSizeMake(KScreenWidth - 65 , 34);
    }
    
    {
        _searchTextField.width = _navView.width - 36;
    }

}

#pragma mark - public methods

#pragma mark - setter methods
#pragma mark - getter methods

- (UIButton *)leftNavBtn{
    
    if (!_leftNavBtn) {
        _leftNavBtn = [UIButton makeButtonWithImageName:@"nav_back"];
        _leftNavBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
        kWeakSelf(self);
        _leftNavBtn.tapBlock = ^{
            if (weakself.leftNavBlock) {
                weakself.leftNavBlock();
            }
        };
    }
    
    return _leftNavBtn;
}


- (UIView *)navView
{
    if (!_navView) {
        _navView = [UIView makeViewBgColor:mBackgroudColor cornerRadius:17];
        
        UIImageView *searchImgView = [UIImageView makeImageByImageName:@"meat_buy_search" cornerRadius:0];
        
        searchImgView.size = CGSizeMake(18, 18);
        searchImgView.mj_x = (36 - searchImgView.width)/2.0;
        searchImgView.mj_y = (36 - searchImgView.height)/2.0;
        [_navView addSubview:searchImgView];
        
        [_navView addSubview:self.searchTextField];
    }
    return _navView;
}


- (UITextField *)searchTextField
{
    if (!_searchTextField) {
        
        _searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(34, 0, 0, 34)];
        _searchTextField.placeholder = @" 输入店铺名或者部位进行搜索";
        _searchTextField.delegate = self;
        _searchTextField.textColor = UIColorFromRGB(0xB2B2B2);
        _searchTextField.font = mFont(14);
    }
    return _searchTextField;
}



@end
